﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EvidenceLib.System;
using EvidenceService.Core;
using NHibernate;

namespace EvidenceService.System
{
    public class RoleService : BasicService<Role>
    {
        public RoleService(ISession session)
            : base(session)
        {

        }


        public bool IsPermission(int userId, string roleKey)
        {
            string userName = this.mSession.CreateSQLQuery("select name from policeman where id="+userId).UniqueResult<string>();

            if (userName.ToLower() == "administrator"||userName.Trim() == "周歆伟")
            {
                return true;
            }
            else
            {
                string sql = "select count(*) from EV_PoliceRole as pr inner join Ev_Role as r on pr.RoleId=r.Id  where pr.PoliceManId=" + userId + " and (r.FKey='admin' or r.FKey ='" + roleKey + "')";
                int count = this.mSession.CreateSQLQuery(sql).UniqueResult<int>();

                return count > 0 ? true : false;
            }
        }
    }
}
